<?php
App::uses('AppController', 'Controller');
class RealTimeController extends AppController{
    public $uses = array('User','BoxTransaction');
    function beforeFilter(){
        parent::beforeFilter();
        $this->layout = 'font_end';
    }
    function index(){
        $this->set('baseUrl',$this->base);
    }
    function checkPendingCall(){
        $userCurrent    = $this->Auth->user();
        $uidCurrent     = $userCurrent['id'];
        $arrReturn = array();
        if($userCurrent['group_id'] == 2){
            $arrUserPending = array();
            $arrUserPending = $this->BoxTransaction->find('all',array('conditions' => array('user_id' => $uidCurrent)));
            if(!empty($arrUserPending)){
                $arrReturn = array(
                                'code'      =>  1,
                                'total'     =>  sizeof($arrUserPending)
                            );
            }else{
                $arrReturn = array('code' => 0);
            }
        }else{
            $arrUserPending = array();
            $arrUserPending = $this->BoxTransaction->find('all',array('conditions' => array('user_call' => $uidCurrent)));
            if(!empty($arrUserPending)){
                $arrReturn = array(
                                'code'      =>  1,
                                'total'     =>  sizeof($arrUserPending)
                            );
            }else{
                $arrReturn = array('code' => 0);
            }
        }
        $arrDataReturn          = json_encode($arrReturn);
        $this->response->body($arrDataReturn);
		return $this->response;
    }
}